package com.wdd.recoveryvehicle.employeeUser.service.impl;

import com.wdd.recoveryvehicle.employeeUser.bean.EmpInfoVB;
import com.wdd.recoveryvehicle.employeeUser.bean.EmpTypeVB;
import com.wdd.recoveryvehicle.employeeUser.service.EmployeeUserService;
import com.wdd.recoveryvehicle.mapper.EmployeeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EmployeeUserServiceImpl implements EmployeeUserService {
    private Logger logger = LoggerFactory.getLogger(EmployeeUserServiceImpl.class);

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public boolean insertEmpInfo(EmpInfoVB empInfoVB, String user_id, String company_id) {
        return employeeMapper.insertEmpInfo(empInfoVB,user_id,company_id);
    }

    @Override
    public List<EmpInfoVB> selectEmpInfoVBByUseful(String useful, String company_id) {
        List<EmpInfoVB> empInfoVBS = employeeMapper.selectEmpInfoVBByUseful(useful, company_id);
        // 替换客户类型名称
        if (empInfoVBS!=null && empInfoVBS.size()>0){
            for (EmpInfoVB empInfoVB : empInfoVBS) {
                EmpTypeVB empTypeVB = employeeMapper.selectEmpTypeVBByTypeId(empInfoVB.getEmp_type());
                if (empTypeVB != null) {
                    empInfoVB.setEmp_typeName(empTypeVB.getType_name());
                } else {
                    empInfoVB.setEmp_typeName("");
                }
            }
        }
        return empInfoVBS;
    }

    @Override
    public List<EmpInfoVB> selectEmpInfoVBByVehicleId(String vehicle_id) {
        List<String> empIds = employeeMapper.selectEmpIdsByVehicleId(vehicle_id);
        List<EmpInfoVB> empInfoVBS = new ArrayList<>();
        if (empIds!=null && empIds.size()>0){
            for (String emp_id : empIds){
                EmpInfoVB empInfoVB = employeeMapper.selectEmpInfoVBByEmpId(emp_id);
                // 替换客户类型名称
                EmpTypeVB empTypeVB = employeeMapper.selectEmpTypeVBByTypeId(empInfoVB.getEmp_type());
                if (empTypeVB != null) {
                    empInfoVB.setEmp_typeName(empTypeVB.getType_name());
                } else {
                    empInfoVB.setEmp_typeName("");
                }
            }
        }
        return empInfoVBS;
    }

    @Override
    public List<EmpTypeVB> selectEmpTypeVB() {
        return employeeMapper.selectEmpTypeVB();
    }

    @Override
    public List<EmpInfoVB> selectEmpIdNamePhone(String create_company) {
        return employeeMapper.selectEmpIdNamePhone(create_company);
    }

    @Override
    public List<String> selectCountEmpVehicle(String emp_id) {
        return employeeMapper.selectCountEmpVehicle(emp_id);
    }

    @Override
    public boolean updateEmpInfoVB(EmpInfoVB empInfoVB, String user_id) {
        return employeeMapper.updateEmpInfoVB(empInfoVB, user_id);
    }

    @Override
    public boolean updateEmpInfoUsefulWx(String emp_id, String user_id) {
        return employeeMapper.updateEmpInfoUsefulWx(emp_id, user_id);
    }


}
